Previous | Index | Next |

Array iterators

To make it possible for the generic algorithms to work directly with the java build-in arrays, appropriate array iterators are provided. The array itself cannot create the begin and end iterators, therefore static methods in the Array api class can create the iterators based on supplied array. All arrayiterator are of the RandomIterator api type.

For example,

     Object[] arr;
     Vector vector = new Vector(10, null);
     ...
     Algo.copy(Array.begin(arr), Array.end(arr), vector.begin());
copies the elements in the array arr into the vector.

Array iterators exits for arrays of Object, for the individual characters in String and StringBuffer and for all the primitive data types available in the java language. Note that an arra iterator on a String does not support the put() method, because Strings are immutable. StringBuffer however support put().

When an array iterator is used with an array of primitive data, a wrapper object is created for each execution of the get() method. This makes array iterators very fine for creating objects based on data in arrays, but they are rather slow when used for scanning through the entire array and for updating the array. The type wrapper used depends on the array type.

Primitive type Wrapper class
byte Integer
short Integer
int Integer
float Float
double Double
char Character
boolean Boolean


Previous | Index | Next |